package com.np.adapterdemo1;

import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;

import java.io.Serializable;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ActivityResultLauncher<Intent> launcher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
            @Override
            public void onActivityResult(ActivityResult result) {
                if (result != null && result.getResultCode() == RESULT_OK && result.getData() != null) {
                    Serializable entity = result.getData().getSerializableExtra("entity");
                }
            }
        });

        findViewById(R.id.button_01).setOnClickListener(v -> launcher.launch(new Intent(this, ArrayAdapterActivity.class)));
        findViewById(R.id.button_02).setOnClickListener(v -> launcher.launch(new Intent(this, ArrayAdapterSecondActivity.class)));
        findViewById(R.id.button_03).setOnClickListener(v -> launcher.launch(new Intent(this, SimpleAdapterActivity.class)));
        findViewById(R.id.button_04).setOnClickListener(v -> launcher.launch(new Intent(this, SimpleAdapterSecondActivity.class)));
        findViewById(R.id.button_05).setOnClickListener(v -> launcher.launch(new Intent(this, SimpleCursorAdapterActivity.class)));
        findViewById(R.id.button_06).setOnClickListener(v -> launcher.launch(new Intent(this, BaseAdapterActivity.class)));
    }
}